/**
 * 
 */
package com.jonosoft.photocast.viewer.web.client.ui.imagecollections;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.jonosoft.photocast.viewer.web.client.ImageCollection;
import com.jonosoft.photocast.viewer.web.client.ui.LibraryImage;

/**
 * TODO Add description ImageCollectionsByTitleMenuItem (com.jonosoft.photocast.viewer.web.client.ui.imagecollections.ImageCollectionsByTitleMenuItem)
 *
 * @author jon
 *
 */
public class ImageCollectionsByTitleMenuItem extends ImageCollectionsMenuItem
        implements HasSubMenu {

	public ImageCollectionsByTitleMenuItem(ImageCollection imageCollection) {
		super(imageCollection);
		setText(imageCollection.getTitle());
	}
	
	/**
	 * @see com.jonosoft.photocast.viewer.web.client.ui.imagecollections.HasSubMenu#getSubMenuItems()
	 */
	public List getSubMenuItems() {
		ArrayList submenuItems = new ArrayList();
		Iterator i = getListOfYears().iterator();
		
		while (i.hasNext()) {
			Integer year = (Integer) i.next();
			submenuItems.add(new ImageCollectionsByYearMenuItem(imageCollection, year.toString()));
		}

		return submenuItems;
	}

	private List getListOfYears() {
		ArrayList years = new ArrayList();
		Iterator i = imageCollection.iterator();
		Integer year = null;
		
		while (i.hasNext()) {
			year = new Integer(((LibraryImage) i.next()).getPhotoDate().getYear() + 1900);
			if (!years.contains(year))
				years.add(year);
		}

		return years;
	}
}
